<template>
    <div class="input-content">
        <yh-form label-width="110px" :model="inputForm" ref="inputForm">
            <yh-form-item label="申报代码" prop="reportCode">
                <yh-input v-model="inputForm.reportCode" placeholder="请输入"></yh-input>
            </yh-form-item>
            <yh-form-item label="市场代码" prop="marketCode">
                <yh-select v-model="inputForm.marketCode" placeholder="请选择">
                    <yh-option
                        v-for="item in marketCodeSelectData"
                        :key="item.dictKey"
                        :label="item.dictKey + ' ' + item.dictKeyName"
                        :value="item.dictKey"
                    >
                    </yh-option>
                </yh-select>
            </yh-form-item>
            <yh-form-item label="证券类型" prop="stockType">
                <yh-select v-model="inputForm.stockType" placeholder="请选择">
                    <yh-option
                        v-for="item in stockTypeSelectData"
                        :key="item.dictKey"
                        :label="item.dictKey + ' ' + item.dictKeyName"
                        :value="item.dictKey"
                    >
                    </yh-option>
                </yh-select>
            </yh-form-item>
            <yh-form-item label="发行人代码" prop="issueCode">
                <yh-select v-model="inputForm.issueCode" placeholder="请选择">
                    <yh-option
                        v-for="item in issueCodeSelectData"
                        :key="item.dictKey"
                        :label="item.dictKey + ' ' + item.dictKeyName"
                        :value="item.dictKey"
                    >
                    </yh-option>
                </yh-select>
            </yh-form-item>
            <yh-form-item label="上市日期" prop="listDate">
                <el-date-picker v-model="inputForm.listDate" type="date" value-format="yyyyMMdd" placeholder="选择日期"> </el-date-picker>
            </yh-form-item>
            <yh-form-item label="证券名称" prop="stockName">
                <yh-input v-model="inputForm.stockName" placeholder="请输入"></yh-input>
            </yh-form-item>
            <yh-form-item label="面值" prop="faceValue">
                <yh-input-number v-model="inputForm.faceValue" controls-position="right" :min="1" :max="10"></yh-input-number>
            </yh-form-item>
            <yh-form-item label="更多分类" prop="moreType">
                <yh-select v-model="inputForm.moreType" placeholder="请选择">
                    <yh-option
                        v-for="item in moreTypeSelectData"
                        :key="item.dictKey"
                        :label="item.dictKey + ' ' + item.dictKeyName"
                        :value="item.dictKey"
                    >
                    </yh-option>
                </yh-select>
            </yh-form-item>
            <yh-form-item label="是否非公开发行" prop="limitValid">
                <yh-select v-model="inputForm.limitValid" placeholder="请选择">
                    <yh-option v-for="item in limitOptions" :key="item.dictKey" :label="item.dictKey + ' ' + item.dictKeyName" :value="item.dictKey">
                    </yh-option>
                </yh-select>
            </yh-form-item>
            <el-form-item>
                <yh-button @click="handleReset">重置</yh-button>
                <yh-button type="primary" @click="handleSubmit">提交</yh-button>
            </el-form-item>
        </yh-form>
    </div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import { objToArr, SGU_CACHE } from '@/utils/diction-const-util';
import Index from '../dict/index';

@Component({
    name: 'NotStandInput',
})
export default class NotStandInput extends Vue {
    // 非标录入表单
    inputForm = {
        reportCode: '', // 申报代码
        marketCode: '', // 市场代码
        stockType: '', // 证券类型
        issueCode: '', // 发行人代码
        listDate: '', // 上市日期
        stockName: '', // 证券名称
        faceValue: '1', // 面值
        moreType: '', // 更多分类
        limitValid: '0', // 是否非公开发行
    };

    dict: any = new Index();

    marketCodeSelectData: any[] = []; // 市场代码下拉数据

    stockTypeSelectData: any[] = []; // 证券类型下拉数据

    issueCodeSelectData: any[] = []; // 发行人代码下拉数据

    moreTypeSelectData: any[] = []; // 更多分类下拉数据

    // 是否非公开发行下拉数据
    limitOptions = [
        { dictKey: '0', dictKeyName: '否' },
        { dictKey: '1', dictKeyName: '是' },
    ];

    // 校验规则
    rules = {
        reportCode: [
            { required: true, trigger: 'blur' },
            { max: 20, trigger: 'blur' },
        ],
    };

    async mounted() {
        // 获取证券类型下拉数据 stockType
        this.stockTypeSelectData = objToArr(this.dict.stockType);
        // 获取更多分类下拉数据
        this.moreTypeSelectData = objToArr(this.dict.moreType);
        // 获取市场代码下拉数据
        this.marketCodeSelectData = await SGU_CACHE('MarketCode', '/dict/market/list', []);
        // 获取发行人代码下拉数据
        this.$axios.post('/dict/issue/select', {}).then((res: any) => {
            this.issueCodeSelectData = res;
        });
    }

    // 校验提交参数
    verifyParam() {
        let param = this.inputForm;
        if (!param.reportCode) {
            this.yh_message_error('申报代码不可为空');
            return false;
        }
        if (!param.marketCode) {
            this.yh_message_error('市场代码不可为空');
            return false;
        }
        if (!param.stockType) {
            this.yh_message_error('证券类型不可为空');
            return false;
        }
        if (!param.issueCode) {
            this.yh_message_error('发行人代码不可为空');
            return false;
        }
        if (!param.listDate) {
            this.yh_message_error('上市日期不可为空');
            return false;
        }
        if (!param.stockName) {
            this.yh_message_error('证券名称不可为空');
            return false;
        }
        if (!param.faceValue) {
            this.yh_message_error('面值不可为空');
            return false;
        }
        if (!param.moreType) {
            this.yh_message_error('更多分类不可为空');
            return false;
        }
        if (!param.limitValid) {
            this.yh_message_error('是否非公开发行不可为空');
            return false;
        }
        return true;
    }

    // 重置录入表单
    handleReset() {
        (this.$refs.inputForm as any).resetFields();
    }

    // 表单提交
    handleSubmit() {
        if (!this.verifyParam()) {
            return;
        }
        this.$axios
            .post('/dataEngine/nonStandard', this.inputForm)
            .then(res => {
                this.yh_message_success('录入成功');
                this.handleReset();
            })
            .catch(err => {
                console.log(err);
            });
    }
}
</script>
<style lang="scss" scoped>
.input-content {
    width: 360px;
    padding: 10px 15px;
    /deep/.el-input__inner {
        height: 32px !important;
        width: 220px;
    }
    /deep/.el-form-item {
        margin-bottom: 5px !important;
        .el-form-item__label {
            color: #575757;
        }
    }
    /deep/.el-input-number {
        line-height: 30px;
        .el-input-number__decrease,
        .el-input-number__increase {
            line-height: 15px;
        }
    }
}
</style>
